<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="../../react18/react.development.js"></script>
    <script src="../../react18/react-dom.development.js"></script>
    <script src="../../react18/babel.min.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <button>点击重新创建虚拟DOM并渲染</button>
    <script type="text/babel">
      let btn = document.querySelector("button");
      //   获取按钮绑定事件
      const vDOM = (
        <div>
          <p>这里是p元素</p>
          <div>
            <span>我是span元素</span>
            <em>我是em倾斜</em>
            <p></p>
          </div>
        </div>
      );
      //   创建虚拟DOM对象1
      const root = ReactDOM.createRoot(document.querySelector("#app"));
      root.render(vDOM);
      //   获取根容器并在根容器内渲染虚拟DOM

      btn.onclick = function () {
        const vDOM = (
          <div>
            <p>这里是p元素</p>
            <div>
              <em>我是em倾斜</em>
              <span>我是span元素</span>
              <p></p>
            </div>
          </div>
        );
        //   创建虚拟DOM对象2
        root.render(vDOM);
        // 将虚拟DOM对象2渲染到跟容器app内
      };
    </script>
  </body>
</html>
